/*
 * Copyright 2003 Program of Computer Graphics, Cornell University
 *     580 Rhodes Hall
 *     Cornell University
 *     Ithaca NY 14853
 * Web: http://www.graphics.cornell.edu/
 * 
 * Not for commercial use. Do not redistribute without permission.
 */
#include "stdafx.h"

#include "Scene.h"

Scene::~Scene()
{
  if (full) {
    full->removeAll();
    delete full;
    full = NULL;
  }
  if (geomPool) {
    delete geomPool;
  }
  if (tree) {
    delete tree;
    tree = NULL;
  }
}

void Scene::addGeometryObject(GeometryObject *obj)
{
  if (full==NULL) {
    full = new GeometrySet();
  }
  full->add(obj);
}

void Scene::buildFlatList() 
{
  KDBuilder *flat = new KDBFlatList();
  if (tree) delete tree;
  //note uncompiled geometry is deleted as part of the tree build process
  tree = new KDTree(flat,this);
  delete flat;
}

void Scene::buildNaiveMiddleSplit(int depth)
{
  KDBNaiveMiddleSplit middle(depth);
  if (tree) delete tree;
  //note uncompiled geometry is deleted as part of the tree build process
  tree = new KDTree(&middle,this);
}

void Scene::buildNaiveMedianSplit(int maxElementsPerLeaf)
{
  KDBNaiveMedianSplit median(maxElementsPerLeaf);
  if (tree) delete tree;
  //note uncompiled geometry is deleted as part of the tree build process
  tree = new KDTree(&median,this);
}

void Scene::buildGreedySplit()
{
  KDBuilder *greedy = new KDBGreedyCostSplit();
  if (tree) delete tree;
  //note uncompiled geometry is deleted as part of the tree build process
  tree = new KDTree(greedy,this);
  delete greedy;
}

